﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Data;
//using System.Data.Sql;
//using System.Data.SqlClient;
//using Microsoft.SqlServer;

//namespace DbInserter
//{5
//    class Program
//    {
//        static private void Insert()
//        {
//            string connectingStr = GetConnectingString();

//            using( SqlConnection connection = new SqlConnection( connectingStr ) )
//            {
//                string inscmd = @"
//					BULK INSERT [dbo].[Table_2] 
//					FROM 'C:\outputs.csv'
//					WITH ( FIRSTROW = 2, FIELDTERMINATOR = ',',ROWTERMINATOR = '\n', CODEPAGE= 65001 )";

//                SqlCommand insertCommand = new SqlCommand( inscmd, connection );

//                connection.Open();
//                Console.WriteLine( "ServerVersion: {0}", connection.ServerVersion );
//                Console.WriteLine( "State: {0}", connection.State );

//                Console.WriteLine( "Inserting Data..." );

//                SqlDataReader reader = null;
//                try
//                {
//                    reader = insertCommand.ExecuteReader();
//                }
//                catch( SqlException exception )
//                {
//                    Console.WriteLine( exception.ToString() );
//                }
//                finally
//                {
////					reader.Close();
//                }
//            }
//            Console.WriteLine( "Insert is over..." );
//        }

//        static void Main( string[] args )
//        {
//            Insert();		

//    //		CeekTestDataContext db = new CeekTestDataContext();
//    //		var s = from record in db.CeekTest2
//    //				where record.ElementName == "User"
//    //				select record.Value;

//            //using( System.IO.StreamWriter writer = new System.IO.StreamWriter( @"outputs.txt" ) )
//            //{
//            //    foreach( var record in s )
//            //    {
//            //        writer.WriteLine( record );
//            //        Console.WriteLine( record );

//            //        //if( i < 10 )
//            //        //{
//            //        //    //byte[] sjisByte = s_jis.GetBytes( record );
//            //        //    //byte[] unicodeByte = Encoding.Convert( s_jis, unicode, sjisByte );
//            //        //    //char[] unicodeChar = new char[unicode.GetCharCount( unicodeByte, 0, unicodeByte.Length )];
//            //        //    //unicode.GetChars( unicodeByte, 0, unicodeByte.Length, unicodeChar, 0 );
//            //        //    //Console.WriteLine( new string( unicodeChar ) );

//            //        //    Console.WriteLine( record );

//            //        //    i++;
//            //        //}
//            //        //else 
//            //        //{ 
//            //        //    break; 
//            //        //}
//            //    }

//            //    writer.Close();
//            //}

//    //		Console.WriteLine( "outputs is over..." );
//            Console.ReadKey();
//        }

//        private static string GetConnectingString()
//        {
//            return @"Data Source=HIROYUKI-6B2E33\SQLEXPRESS;Initial Catalog=FloridumDb;Integrated Security=True";
//        }
//    }
//}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using Microsoft.SqlServer;

namespace DbInserter
{
	class Program
	{
		static private void Insert()
		{
			string connectingStr = GetConnectingString();

			using ( SqlConnection connection = new SqlConnection( connectingStr ) )
			{
				string inscmd = @"
					BULK INSERT [dbo].[Table_2] 
					FROM 'C:\build.csv'
					WITH ( FIRSTROW = 2, FIELDTERMINATOR = ',',ROWTERMINATOR = '\n', CODEPAGE= 65001 )";

				SqlCommand insertCommand = new SqlCommand( inscmd, connection );

				connection.Open();
				Console.WriteLine( "ServerVersion: {0}", connection.ServerVersion );
				Console.WriteLine( "State: {0}", connection.State );

				Console.WriteLine( "Inserting Data..." );

				SqlDataReader reader = null;
				try
				{
					reader = insertCommand.ExecuteReader();
				}
				catch ( SqlException exception )
				{
					Console.WriteLine( exception.ToString() );
				}
				finally
				{
					reader.Close();
				}
			}
			Console.WriteLine( "Insert is over..." );
		}

		static void Main( string[] args )
		{
//			Insert();

			CeekTestDataContext db = new CeekTestDataContext();
			var s = from record in db.Table_2
					where record.Depth == 2
					select record.NodeType;

			//using( System.IO.StreamWriter writer = new System.IO.StreamWriter( @"outputs.txt" ) )
			//{
			foreach ( var record in s )
			{
				Console.WriteLine( record.ToString() );
			}

			//        writer.WriteLine( record );
			//        Console.WriteLine( record );

			//        //if( i < 10 )
			//        //{
			//        //    //byte[] sjisByte = s_jis.GetBytes( record );
			//        //    //byte[] unicodeByte = Encoding.Convert( s_jis, unicode, sjisByte );
			//        //    //char[] unicodeChar = new char[unicode.GetCharCount( unicodeByte, 0, unicodeByte.Length )];
			//        //    //unicode.GetChars( unicodeByte, 0, unicodeByte.Length, unicodeChar, 0 );
			//        //    //Console.WriteLine( new string( unicodeChar ) );

			//        //    Console.WriteLine( record );

			//        //    i++;
			//        //}
			//        //else 
			//        //{ 
			//        //    break; 
			//        //}
			//    }

			//    writer.Close();
			//}

			//Console.WriteLine( "outputs is over..." );
			Console.ReadKey();
		}

		private static string GetConnectingString()
		{
			return @"Data Source=HIROYUKI-6B2E33\SQLEXPRESS;Initial Catalog=FloridumDb;Integrated Security=True";
		}
	}
}

